package es.gesfutbol.domini.implementacio;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import es.gesfutbol.domini.IPenyista;

@Entity
@Table(name="penyista")
public class Penyista implements IPenyista {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4605843820296360998L;

	private Long idPenyista;
	
	private UsuariRegistrat usuari;
	
	private Penya penya;
	
	private boolean administra;
	
	private boolean pronostica;
	
	private boolean aporta;

	private Set<Comentari> comentaris;
	
	private Set<Pronostic> pronostics;
	
	private Set<EquipEnPenyista> equips;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="idPenyista", nullable=false, precision = 10, scale=0)
	public Long getIdPenyista() {
		return idPenyista;
	}

	public void setIdPenyista(Long idPenyista) {
		this.idPenyista = idPenyista;
	}

//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumn(name="idUsuari" , nullable=false)
	@OneToOne
	@JoinColumn(name="idUsuari", referencedColumnName = "idUsuari", nullable = false)	
	public UsuariRegistrat getUsuari() {
		return usuari;
	}

	public void setUsuari(UsuariRegistrat usuari) {
		this.usuari = usuari;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="idPenya" , nullable=false)
	public Penya getPenya() {
		return penya;
	}

	public void setPenya(Penya penya) {
		this.penya = penya;
	}

	@Column(name="administra",columnDefinition = "tinyint", nullable = false)
	public boolean isAdministra() {
		return administra;
	}

	public void setAdministra(boolean administra) {
		this.administra = administra;
	}

	@Column(name="pronostica",columnDefinition = "tinyint", nullable = false)
	public boolean isPronostica() {
		return pronostica;
	}

	public void setPronostica(boolean pronostica) {
		this.pronostica = pronostica;
	}

	@Column(name="aporta",columnDefinition = "tinyint", nullable = false)
	public boolean isAporta() {
		return aporta;
	}

	public void setAporta(boolean aporta) {
		this.aporta = aporta;
	}

	@OneToMany(fetch= FetchType.LAZY, mappedBy="idComentari", cascade=CascadeType.ALL)
	public Set<Comentari> getComentaris() {
		return comentaris;
	}

	public void setComentaris(Set<Comentari> comentaris) {
		this.comentaris = comentaris;
	}

	@OneToMany(fetch=FetchType.LAZY, mappedBy="penyista", cascade=CascadeType.ALL)
	public Set<Pronostic> getPronostics() {
		return pronostics;
	}

	public void setPronostics(Set<Pronostic> pronostics) {
		this.pronostics = pronostics;
	}

	@OneToMany(fetch=FetchType.LAZY, mappedBy="id.penyista", cascade=CascadeType.ALL)
	public Set<EquipEnPenyista> getEquips() {
		return equips;
	}

	public void setEquips(Set<EquipEnPenyista> equips) {
		this.equips = equips;
	}
}
